import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/util/ext_utils.dart';

import '../../res/gaps.dart';
import '../../viewmodel/device/device_repair_submit_view_model.dart';

class DeviceRepairSubmitFragment extends BaseStatefulMvvmWidget {
  final String? id;
  final String? content;

  DeviceRepairSubmitFragment({this.id, this.content});

  @override
  State<StatefulWidget> createState() => _DeviceRepairSubmitState();
}

class _DeviceRepairSubmitState extends BaseMvvmState<
    DeviceRepairSubmitViewModel, DeviceRepairSubmitFragment> {
  @override
  Widget buildLoadingContentView() {
    return ListView(
      children: [
        CommonText('维保任务时间：${viewModel.taskData?.maintenanceDate?.changeTime(format: [yyyy,'-',mm,'-',dd])}').addToContainer(
            width: double.infinity,
            alignment: Alignment.center,
            margin: EdgeInsets.symmetric(horizontal: 16, vertical: 10),
            decoration: BoxDecoration(
                color: Colors.grey[200], borderRadius: 8.borderRadius),
            padding: EdgeInsets.symmetric(vertical: 10)),
        IconTitleTextWidget(
          '执行时间',
          isRequired: true,
          text: viewModel.finishTime,
        ).onTap(() {
          viewModel.selectFinishTime();
        }),
        Gaps.line,
        IconTitleTextWidget(
          '维保结果',
          isRequired: true,
          text: viewModel.repairResultName,
          hintText: '请选择维保结果',
        ).onTap(() {
          viewModel.selectRepairResult();
        }),
        Gaps.line,
        IconTitleTextWidget(
          '维保内容',
          isRequired: true,
          showArrow: false,
        ),
        CommonInput(
          hintText: '请输入维保内容',
          isDense: true,
          keyboardType: CommonInputType.multiline,
          maxLines: 8,
          padding: EdgeInsets.zero,
          border: InputBorder.none,
          onChanged: (str){
            viewModel.inputContent = str;
          },
        ).addToContainer(
            margin: EdgeInsets.symmetric(horizontal: 16),
            padding: EdgeInsets.all(10),
            decoration: BoxDecoration(
                color: Colors.grey[200], borderRadius: 10.borderRadius)),
        Container(
          height: 40,
        ),
        ElevatedButton(
          onPressed: () {
            viewModel.submitRepair();
          },
          child: CommonText('提交', textColor: Colors.white, textSize: 17),
          style: ButtonStyle(
              backgroundColor: WidgetStateProperty.all(Colours.app_main),
              minimumSize:
                  WidgetStateProperty.all(Size(double.infinity, 50))),
        ).addToContainer(
            margin: EdgeInsets.symmetric(horizontal: 16, vertical: 10))
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return loadingContentWidget;
  }

  @override
  DeviceRepairSubmitViewModel createViewModel() {
    return DeviceRepairSubmitViewModel(context,content: widget.content,id: widget.id);
  }

  @override
  void onRetryClick() {
    viewModel.getTask();
  }
}
